package com.demo.sentinel.command;

/**
 * @ClassName aa
 * @Description TODO
 * @Author hf
 * @Date 2023/2/8 9:46
 * @Version 1.0
 */

import lombok.Data;
import lombok.SneakyThrows;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;


/**
 * @ClassName Desasdf
 * @Description TODO
 * @Author hf
 * @Date 2023/2/6 9:56
 * @Version 1.0
 */
public class TestCb {

    @Data

    static class Monster implements Runnable {
        private Integer index;

        public Monster(Integer index) {
            this.index = index;
        }

        @SneakyThrows
        @Override
        public void run() {
            System.out.println("所有怪物都被消灭，游戏进入第二阶段!");
        }
    }



    public static void main(String[] args) throws InterruptedException, BrokenBarrierException {

         int num = 5;

         CyclicBarrier cyclicBarrier = new CyclicBarrier(num, new Runnable() {

            @SneakyThrows
            @Override
            public void run() {
                System.out.println("所有怪物都被消灭，游戏进入第二阶段!");
            }
        });

        for (int i = 0; i < num; i++) {
            new Thread((Runnable) cyclicBarrier).start();
        }
    }
}

